package practice;

import tree.SegementTree;

public class NumArray {

    //自定义的线段树
    private SegementTree<Integer> segmentTree;

    public NumArray(int[] nums){
        if(nums.length > 0){
            Integer[] data = new Integer[nums.length];
            for (int i = 0; i < nums.length; i++) {
                data[i] = nums[i];
            }

            segmentTree = new SegementTree<>(data,(a,b) -> a+b);

        }
    }

    public int sumRange(int i,int j){
        if(segmentTree == null){
            throw new IllegalArgumentException("segmentTree is IllegalArgumentException");
        }
        //判断i,j的
        return segmentTree.query(i,j);

    }

}
